
'--------------------------------------------------------
' 执行所有测试用例
'--------------------------------------------------------
Public Sub test_all_case()
    ' mergeMapForObjectVal 测试
    test_UtilsMap_mergeMapForObjectVal
    ' mergeMapForPrimitiveVal 测试
    test_UtilsMap_mergeMapForPrimitiveVal
    ' addMapValValToMap 测试
    test_UtilsMap_addMapValValToMap
End Sub

' mergeMapForObjectVal 测试
Private Sub test_UtilsMap_mergeMapForObjectVal()

    Dim map1 As Object
    Set map1 = UtilsCreateSysObj.createMap
    Dim map2 As Object
    Set map2 = UtilsCreateSysObj.createMap

    Dim c1 As Collection
    Set c1 = New Collection
    Dim c2 As Collection
    Set c2 = New Collection
    Dim c3 As Collection
    Set c3 = New Collection

    map1.Add "k1", c1
    map1.Add "k2", c2

    map2.Add "k1", c3
    map2.Add "kx", Nothing

    ' 默认合并 Nothing
    UtilsMap.mergeMapForObjectVal map1, map2

    Debug.Assert map1.Item("k1") Is c3
    Debug.Assert map1.Item("kx") Is Nothing

    Dim map3 As Object
    Set map3 = UtilsCreateSysObj.createMap
    map3.Add "ky", Nothing

    ' 不合并 Nothing
    UtilsMap.mergeMapForObjectVal map1, map3, False
    Debug.Assert map1.Exists("ky") = False
End Sub

' mergeMapForPrimitiveVal 测试
Private Sub test_UtilsMap_mergeMapForPrimitiveVal()
    Dim map1 As Object
    Set map1 = UtilsCreateSysObj.createMap
    Dim map2 As Object
    Set map2 = UtilsCreateSysObj.createMap

    map1.Add "k1", "v1"
    map1.Add "k2", "v2"

    map2.Add "k1", "v3"
    map2.Add "kx", ""

    ' 默认合并 ""
    UtilsMap.mergeMapForPrimitiveVal map1, map2

    Debug.Assert map1.Item("k1") = "v3"
    Debug.Assert map1.Item("kx") = ""

    Dim map3 As Object
    Set map3 = UtilsCreateSysObj.createMap
    map3.Add "ky", ""

    ' 不合并 ""
    UtilsMap.mergeMapForPrimitiveVal map1, map3, False, ""
    Debug.Assert map1.Exists("ky") = False
End Sub

' addMapValValToMap 测试
Private Sub test_UtilsMap_addMapValValToMap()
    Dim k1 As Collection
    Set k1 = New Collection
    Dim v1 As Collection
    Set v1 = New Collection
    Dim k2 As Collection
    Set k2 = New Collection

    ' 1. value 和 某个 key 重复时，覆盖
    Dim map1 As Object
    Set map1 = UtilsCreateSysObj.createMap
    map1.Add k1, v1
    map1.Add k2, k1
    UtilsMap.addMapValValToMap map1

    ' 添加后的数据
    ' k2:k1
    ' v1:v1
    ' k1:k1 (覆盖了 [k1:v1])
    Debug.Assert map1.Count = 3
    Debug.Assert map1.Item(k2) Is k1
    Debug.Assert map1.Item(v1) Is v1
    Debug.Assert map1.Item(k1) Is k1

    ' 2. value 和 某个 key 重复时，跳过
    Dim map2 As Object
    Set map2 = UtilsCreateSysObj.createMap
    map2.Add k1, v1
    map2.Add k2, k1
    UtilsMap.addMapValValToMap map2, False

    ' 添加后的数据
    ' k1:v1 (不会被 k2:k1 中的 k1 覆盖)
    ' k2:k1
    ' v1:v1
    Debug.Assert map2.Count = 3
    Debug.Assert map2.Item(k1) Is v1
    Debug.Assert map2.Item(k2) Is k1
    Debug.Assert map2.Item(v1) Is v1
End Sub